package org.example.service.serviceImpl;

import cn.hutool.core.lang.generator.SnowflakeGenerator;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.entity.Order;
import org.example.mapper.OrderMapper;
import org.example.mapper.UserMapper;
import org.example.service.OrderService;
import org.example.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper,Order> implements OrderService{
    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<Order> getOrderList(Integer id,Integer type) {
        return orderMapper.getOrderList(id,type);
    }

    @Override
    public Integer insertOrder(Order order) {
        order.setUid(Math.toIntExact(ThreadLocalUtil.getCurrentId()));
        order.setOrderNumber(String.valueOf(new SnowflakeGenerator().next()));
        Integer rows=orderMapper.insertOrder(order);
        return rows;
    }

    @Override
    public Order getOrderById(String orderNumber) {
        return orderMapper.getOrderById(orderNumber);
    }

    @Override
    public Integer updateOrderById(Order order) {
        return orderMapper.updateOrderById(order);
    }

    @Override
    public Integer insertScenicOrder(Integer uid, Long orderNumber, String orderName, double price) {
        //对orderNumber雪花算法
        orderNumber =new SnowflakeGenerator().next();
        return orderMapper.insertScenicOrder(uid,orderNumber,orderName,price);
    }
}
